package com.itany.boot.config;

import com.itany.boot.interceptor.LogInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author 石小俊
 */
@Configuration
public class MyConfig implements WebMvcConfigurer {

    /**
     * 配置直接访问试图
     * @param registry
     */
//    @Override
//    public void addViewControllers(ViewControllerRegistry registry) {
//        // 配置访问命令为:/showLogin
//        // 配置视图名为:backend/login
//        registry.addViewController("/showLogin").setViewName("backend/login");
//    }
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 添加一个拦截器,添加时需要指定拦截器是谁
        registry.addInterceptor(new LogInterceptor())
                // 拦截谁,可以调用多次
                .addPathPatterns("/user/**")
                .addPathPatterns("/product/**")
                // 不拦截谁,可以调用多次
                .excludePathPatterns("/user/add")
                .excludePathPatterns("/user/delete")
                .excludePathPatterns("/product/modify");
    }
}
